package com.hisence.web;

import com.hisence.dto.ResultDto;
import com.hisence.pojo.Chuku;
import com.hisence.pojo.Detil;
import com.hisence.pojo.Yaohuo;
import com.hisence.service.CmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.UUID;

@RestController
public class Cmpconlltroer {
    @Autowired
    private CmpService cmpService;
    @RequestMapping("/getcmp")
    private ResultDto Getyaohuo(@RequestBody Yaohuo yaohuo){
        String billno = yaohuo.getBillno();

        ResultDto   resultDto = new ResultDto();
        List<Detil> detils = yaohuo.getDetils();
        StringBuffer s = new StringBuffer("");
        for (Detil detil : detils){
            String shopnum = detil.getShopnum();
            Integer integer = Integer.valueOf(shopnum);
            if (integer>10){
                s.append(detil.getShopname()+"库存不足");
            }
        }
        String s1 = s.toString();
        if ("".equals(s1)){

            try {
                resultDto =  cmpService.insertChuku(yaohuo);

            } catch (Exception e) {
                e.printStackTrace();
                resultDto.setMessage("服务器生成异常");
                resultDto.setStatus(false);
            }
            return resultDto;
        }else {
            resultDto.setMessage(s1);
            resultDto.setStatus(false);
            return resultDto;
        }



    }
}
